﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace CinemabookingWCFApp.TicketsFolder
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TicketsService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select TicketsService.svc or TicketsService.svc.cs at the Solution Explorer and start debugging.
    public class TicketsService : ITicketsService
    {
        #region
        CinemabookingDBDataContext db = new CinemabookingDBDataContext();
        #endregion

        public List<Ticket> GetAllTickets()
        {
            var queryResult = (from x in db.Tickets
                               select x);
            return queryResult.ToList();
        }

        public void SaveTickets(string Tick)
        {
            Ticket saveTick = new Ticket { amount = Tick };
            db.Tickets.InsertOnSubmit(saveTick);
            db.SubmitChanges();
        }

        public void DeleteTickets(string Tick)
        {
            Ticket delTicket = (from x in db.Tickets
                                where x.amount == Tick
                                select x).FirstOrDefault();
            if (delTicket != null)
            {
                db.Tickets.DeleteOnSubmit(delTicket);
                db.SubmitChanges();
            }

        }

    }
}
